import { sys } from "cc";

export default class StorageMgr {

    private static inst:StorageMgr = null;

    public static get Inst():StorageMgr{
        if(!this.inst)this.inst = new StorageMgr();
        return this.inst;
    }
    
    jsonObjs: Map<string, any> = new Map<string , any>();

    getStorage(key: string): string | any {
        console.log("get本地数据",key)
        let k = this.getKey(key);
        return sys.localStorage.getItem(k);
    }
    setStorage(key: string, value: string | any) {
        console.log("本地储存数据",key,value)
        let k = this.getKey(key);
        let v = value;
        sys.localStorage.setItem(k, v);
    }

    storage_all() {
        console.log("初始化数据！");
        let k = UserInfo_Data.name;
        let v = this.getStorage(k);
        console.log(v);
        if(v)this.jsonObjs.set(k, v);
        if(!this.jsonObjs.has(k)){
            v = new UserInfo_Data();
            console.log(k  ," *init userInfo_data* " , v);
            this.jsonObjs.set(k, v);
            this.setStorage(k,v);
        }

    }

    clearAllStorage() {
        sys.localStorage.clear();
    }

    private getKey(key: string): string {
        return key;
    }


}


export class UserInfo_Data{
    /**钱的数量 */
    gold:number = 0;
}
